package com.jjwt.demo;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.util.Date;

/**
 * 解析token
 */
public class ParseToken {
    public static void main(String[] args) {
            //
        String token="eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4ODgiLCJpYXQiOjE1NzMxMjc1MTEsInN1YiI6ImFkbWluIiwiZXhwIjoxNTczMTI3NTcxfQ.xuaUqdK2NACTFbFR_VerkYfHavNEXdU1kl0uXBSf33o";
        Claims zelin = Jwts.parser().setSigningKey("zelin").parseClaimsJws(token).getBody();
        //
        String id = zelin.getId();//得到生成器的id
        Date issuedAt = zelin.getIssuedAt();//得到加密的时间
        String subject = zelin.getSubject();//得到加密的主体
        Date expiration = zelin.getExpiration();//得到过期时间
        System.out.println("id = " + id);
        System.out.println("issuedAt = " + issuedAt);
        System.out.println("subject = " + subject);
        System.out.println("expiration = " + expiration);
    }
}
